{% extends "base.html" %}
{% load kegweblib %}

{% block title %}drink index{% endblock %}
{% block kb-extrajs %}
    <script type="text/javascript">
      // Load the Visualization API and the tablepackage.
      google.load('visualization', '1', {'packages':['table']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(buildTable);

      function buildTable() {
        var data = new google.visualization.DataTable();
        data.addColumn('number', 'Drink');
        data.addColumn('number', 'Ounces');
        data.addColumn('number', 'Calories');
        data.addColumn('string', 'User');
        data.addColumn('string', 'When');
        data.addColumn('number', 'PBAC');
        data.addRows({{drink_list.count}});

        {% for drink in drink_list %}
        data.setCell({{forloop.counter0}}, 0, {{drink.seqn}},
            '<a href="{% url drink drink.seqn %}">{{drink.seqn}}</a>');
        data.setCell({{forloop.counter0}}, 1, {{drink.Volume.ConvertTo.Ounce}},
          '{{drink.Volume.ConvertTo.Ounce|floatformat}}');
        {% if drink.calories %}
        data.setCell({{forloop.counter0}}, 2, {{drink.calories}},
          '{{drink.calories|floatformat}}');
        {% endif %}
        data.setCell({{forloop.counter0}}, 3,
        {% if drink.user %}
        '<a href="{%url pykeg.web.kegweb.views.user_detail drink.user.username %}">{{ drink.user}}</a>');
        {% else %}
        'guest');
        {% endif %}
        data.setCell({{forloop.counter0}}, 4, '{% timeago drink.starttime %}');
        data.setCell({{forloop.counter0}}, 5, {{drink.bac}}, '{{drink.bac|bac_format}}');
        {% endfor %}
        var table = new google.visualization.Table(document.getElementById('kb-keg-drinks-table'));
        var formatter = new google.visualization.BarFormat({width: 50});
        formatter.format(data, 1);
        table.draw(data, {
          showRowNumber: false,
          allowHtml: true,
          page: 'enable',
          pageSize: 20});

        $("#kb-keg-drinks-table").find("abbr.timeago").timeago();
      }

    </script>
{% endblock kb-extrajs %}


{% block content %}
<div class="kb-main-content">
  <div class="kb-contentbox-head">
     full drink history
  </div>
  <div class="kb-contentbox">
    <p>
       full drink history for keg {{ keg.seqn }} is shown below.
    </p>
    <table id="kb-keg-drinks-table" cellspacing=0 border=0></table>
  </div>
</div>
{% endblock %}
